package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.web.service.SysRegisterService;
import com.ruoyi.system.domain.Tourist;
import com.ruoyi.system.service.ITouristService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 旅客Controller
 *
 * @author 强盛酒店
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/system/tourist")
public class TouristController extends BaseController {
    @Autowired
    private ITouristService touristService;
    @Autowired
    private SysRegisterService registerService;
    /**
     * 查询旅客列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Tourist tourist) {
        startPage();
        List<Tourist> list = touristService.selectTouristList(tourist);
        return getDataTable(list);
    }

    /**
     * 获取旅客详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(touristService.selectTouristById(id));
    }

    /**
     * 获取旅客详细信息
     */
    @GetMapping(value = "/detail")
    public AjaxResult getInfo() {
        return success(touristService.selectTouristById2());
    }

    /**
     * 新增旅客
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Valid Tourist tourist) {
        registerService.validateCaptcha(tourist.getName(),tourist.getCode(),tourist.getUuid());
        return toAjax(touristService.insertTourist(tourist));
    }

    /**
     * 修改旅客
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Tourist tourist) {
        return toAjax(touristService.updateTourist(tourist));
    }

    /**
     * 修改旅客
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Tourist tourist) {
        return toAjax(touristService.updateTourist2(tourist));
    }

    /**
     * 删除旅客
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(touristService.deleteTouristByIds(ids));
    }

    /**
     * 重置密码
     */
    @PutMapping("/rest")
    public AjaxResult rest(@RequestBody Tourist tourist) {
        return toAjax(touristService.rest(tourist));
    }
}
